allow to create war archive without copying massive files to exploded… - #21
Open
caiwei-ebay wants to merge 1 commit into
Open
allow to create war archive without copying massive files to exploded…#21caiwei-ebay wants to merge 1 commit into
caiwei-ebay wants to merge 1 commit into
Conversation
Member
|
Doens't this only make sense in |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
This PR introduces an option to build the WAR archive directly from source paths (skipping most copies into an exploded webapp directory) to speed up maven-war-plugin execution.
Changes:
- Added
WarResourceCopyto track source→target mappings and optionally skip physical copies. - Added
SourceTargetMappingResourceFilterto apply include/exclude filtering over the collected mappings and feed resources directly toWarArchiver. - Extended packaging flow and context APIs to support
skipExplodedWarCreation, and updatedWarMojo/ classes packaging to use the new mode.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/org/apache/maven/plugins/war/util/WarResourceCopy.java | New helper to record file mappings and optionally avoid copying. |
| src/main/java/org/apache/maven/plugins/war/util/SourceTargetMappingResourceFilter.java | New filtering/scanning layer to convert mappings into PlexusIoResources for archiving. |
| src/main/java/org/apache/maven/plugins/war/util/ClassesPackager.java | Added an overload to package classes from an explicit (path→file) mapping. |
| src/main/java/org/apache/maven/plugins/war/packaging/WarProjectPackagingTask.java | Adjusted logging to reflect “collecting” vs “copying” behavior. |
| src/main/java/org/apache/maven/plugins/war/packaging/WarPackagingContext.java | Added skipExplodedWarCreation() and getWarResourceCopy() hooks to the context API. |
| src/main/java/org/apache/maven/plugins/war/packaging/ClassesPackagingTask.java | Records generated artifact mapping (WEB-INF/lib) into WarResourceCopy. |
| src/main/java/org/apache/maven/plugins/war/packaging/AbstractWarPackagingTask.java | Routes file-copy operations through WarResourceCopy and records mappings. |
| src/main/java/org/apache/maven/plugins/war/WarMojo.java | Builds WAR from mappings when skip mode is enabled, with a fallback addDirectory pass. |
| src/main/java/org/apache/maven/plugins/war/AbstractWarMojo.java | Adds plugin parameter + propagates skip flag and returns WarPackagingContext from build methods. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| boolean archiveClasses(); | ||
|
|
||
| /** | ||
| * Skip explded war creation, build web archive on source paths. |
| * @throws MojoFailureException In case of failure. | ||
| */ | ||
| public void buildExplodedWebapp( File webapplicationDirectory ) | ||
| public WarPackagingContext buildExplodedWebapp( File webapplicationDirectory ) |
| * @throws IOException if an error occurred while copying the files | ||
| */ | ||
| public void buildWebapp( MavenProject mavenProject, File webapplicationDirectory ) | ||
| public WarPackagingContext buildWebapp( MavenProject mavenProject, File webapplicationDirectory ) |
Comment on lines
+383
to
+384
| @Parameter( defaultValue = "false", name = "maven.war.exploded.skip" ) | ||
| private boolean skipExplodedWarCreation; |
Comment on lines
+253
to
+258
| Map<String, File> map = context.getWarResourceCopy().getSourceTargetMappings(); | ||
| if ( map.containsKey( "WEB-INF/web.xml" ) ) | ||
| { | ||
| warArchiver.setWebxml( map.get( "WEB-INF/web.xml" ) ); | ||
| map.remove( "WEB-INF/web.xml" ); | ||
| } |
Comment on lines
+274
to
+278
| Set<String> targetPaths = context.getWarResourceCopy().getSourceTargetMappings().keySet(); | ||
| Set<String> newExcludes = new HashSet<>( targetPaths ); | ||
| newExcludes.addAll( Arrays.asList( getPackagingExcludes() ) ); | ||
| warArchiver | ||
| .addDirectory( getWebappDirectory(), getPackagingIncludes(), newExcludes.toArray( new String[0] ) ); |
Comment on lines
+59
to
+62
| for ( Map.Entry<String, File> entry : allClassFiles.entrySet() ) | ||
| { | ||
| archiver.getArchiver().addFile( entry.getValue(), entry.getKey() ); | ||
| } |
Comment on lines
+126
to
+167
| ds.setFilenameComparator( fileNameComparator ); | ||
| ds.scan(); | ||
|
|
||
| final Map<String, PlexusIoResource> result = new HashMap<>(); | ||
| if ( isIncludingEmptyDirectories() ) | ||
| { | ||
| String[] dirs = ds.getIncludedDirectories(); | ||
| addResources( result, dirs ); | ||
| } | ||
|
|
||
| String[] files = ds.getIncludedFiles(); | ||
| addResources( result, files ); | ||
| return result; | ||
| } | ||
|
|
||
| private void addResources( Map<String, PlexusIoResource> result, String[] resources ) | ||
| throws IOException | ||
| { | ||
|
|
||
| final HashMap<Integer, String> cache1 = new HashMap<>(); | ||
| final HashMap<Integer, String> cache2 = new HashMap<>(); | ||
| for ( String name : resources ) | ||
| { | ||
| File f = sourceTargetMappings.get( name ); | ||
| if ( f != null ) | ||
| { | ||
| PlexusIoResourceAttributes attrs = new FileAttributes( f, cache1, cache2 ); | ||
| attrs = mergeAttributes( attrs, f.isDirectory() ); | ||
|
|
||
| String remappedName = getName( name ); | ||
|
|
||
| PlexusIoResource resource = | ||
| ResourceFactory.createResource( f, remappedName, null, getStreamTransformer(), attrs ); | ||
|
|
||
| if ( isSelected( resource ) ) | ||
| { | ||
| result.put( name, resource ); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } |
Comment on lines
+372
to
+396
| String[] tokenizedName = tokenizePathToString( name, "/" ); | ||
| if ( file.isFile() ) | ||
| { | ||
| if ( isIncluded( name, tokenizedName ) ) | ||
| { | ||
| if ( !isExcluded( name, tokenizedName ) ) | ||
| { | ||
| filesIncluded.addElement( name ); | ||
| } | ||
| else | ||
| { | ||
| everythingIncluded = false; | ||
| filesExcluded.addElement( name ); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| everythingIncluded = false; | ||
| filesNotIncluded.addElement( name ); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| throw new IllegalStateException( "Should not be here" ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MWAR-445
This PR is initialized for discussion.
Basically the idea is to create the war archive without massive file copyings to exploded war directory to make maven-war-plugin run faster.
Please share your thoughts on it.